package com.cl.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cl.blog.common.Const;
import com.cl.blog.entity.BContent;
import com.cl.blog.entity.BHistoryLook;
import com.cl.blog.mapper.BContentMapper;
import com.cl.blog.service.BContentService;
import com.cl.blog.service.BHistoryLookService;
import com.cl.blog.mapper.BHistoryLookMapper;
import com.cl.blog.util.JwtUtil;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author object
 * @description 针对表【b_history_look】的数据库操作Service实现
 * @createDate 2024-03-14 17:13:59
 */
@Service
public class BHistoryLookServiceImpl extends ServiceImpl<BHistoryLookMapper, BHistoryLook>
		implements BHistoryLookService {

	@Autowired
	JwtUtil jwtUtil;
	@Autowired
	BContentMapper bContentMapper;

	@Override
	public Object selectAll(HttpServletRequest request) {
		String token = request.getHeader("token");
		Claims claim = jwtUtil.getClaimByToken(token, Const.GRADE_USER);
		List<BHistoryLook> bHistoryLooks = this.list(new QueryWrapper<BHistoryLook>()
				.eq("user_id", Integer.valueOf(claim.getSubject()))
				.orderByDesc("create_time")
		);
		if (bHistoryLooks.size() <= 0) {
			return null;
		}
		for (BHistoryLook bHistoryLook : bHistoryLooks) {
			BContent bContent = bContentMapper.selectById(bHistoryLook.getContentId());
			bHistoryLook.setBContent(bContent);
		}
		return bHistoryLooks;
	}
}




